﻿#ifndef UDPSERVER_H
#define UDPSERVER_H

#include <QObject>
#include <QUdpSocket>
#include <QJsonValue>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>

class UdpServer : public QObject
{
    Q_OBJECT
public:
    explicit UdpServer(QObject *parent = 0);
    ~UdpServer();
    Q_INVOKABLE void sendCommand(QVariant lockID, char index, char cmd, QVariant buf, QString sender, int port);
private:
    int valist2array(QByteArray &arr, QVariant &data);
    int array2valist(QVariant &data, QByteArray &arr);
    void mysql_init();
    void mysql_table(QByteArray data);
    unsigned short crc16_update(unsigned short crc, unsigned char a);
    unsigned short usCRC16(const char *pucFrame, int usLen);
signals:
    void lockStatusChanged(QVariant status, QString sender, quint16 senderPort);
public slots:
    void readPendingDatagrams();
private:
    QUdpSocket udpSocket;
    //unsigned short port;
};

#endif // UDPSERVER_H
